package com.qk.service.impl;

import com.qk.entity.OverViewVo;
import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.OverviewService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class OverviewServiceImpl implements OverviewService {

    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public OverViewVo overview() {
        Object overview = redisTemplate.opsForValue().get("overview");
        log.info("从redis中获取数据");

        if (overview !=null){
            return (OverViewVo) overview;
        }
        OverViewVo ov = clueMapper.overviewClue();

        OverViewVo ov2 = businessMapper.overviewBusiness();
        BeanUtils.copyProperties(ov,ov2,"businessTotal","businessWaitAllot","businessWaitFollow","businessFollowing","businessFalse","businessConvertCustomer");
        redisTemplate.opsForValue().set("overview",ov2,1, TimeUnit.MINUTES);
        return ov2;
    }
}
